﻿namespace Lite.Messaging.Msmq
{
    using System.Messaging;
    using System.Runtime.Serialization.Formatters;

    /// <summary>
    /// A static factory for creating and caching a IMessageFormatter instance.
    /// </summary>
    /// <remarks>
    /// All messages should use this instance of IMessageFormatter to ensure
    /// consistently between serialisation and deserialisation.
    /// </remarks>
    internal static class FormatterFactory
    {
        /// <summary>
        /// The internal store for the IMessageFormatter instance.
        /// </summary>
        private static readonly IMessageFormatter instance = new BinaryMessageFormatter(FormatterAssemblyStyle.Full, FormatterTypeStyle.TypesWhenNeeded);

        /// <summary>
        /// Gets the singleton instance of IMessageFormatter for use by all
        /// serialisers in this library.
        /// </summary>
        public static IMessageFormatter Formatter
        {
            get
            {
                return instance;
            }
        }
    }
}
